/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 1

Using: Hw1Types.h

Description:
A simple logger module that writes to a text file determined by the 
LoggerInitialize function
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#define _CRT_SECURE_NO_WARNINGS
#include "Logger.h"
#include "General.h"


FILE* LoggerInitialize(char* filename)
{
	loggerFile = fopen(filename, "w");

	// I'm not asserting here on purpose. Log shouldn't bring down the whole program

	return loggerFile;
}

void LoggerWriteMessage(char* message)
{
	// For debug purposes
	// printf("%s \n", message);

	if (loggerFile != NULL)
		fprintf(loggerFile, "%s\n", message);
}

void LogBuyFromSupplier(char* productName, char* customerName, TMoney price)
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Bought %s from %s for %.2f Shekels", productName, customerName, price);
	LoggerWriteMessage(message);
}

void LogBuyFromSupplierFailure(char* productName, char* customerName, TMoney price)
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Did not buy %s from %s", productName, customerName);
	LoggerWriteMessage(message);
}

void LogSellToCustomer(char* productName, char* customerName, TMoney price)
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Sold %s to %s for %.2f Shekels", productName, customerName, price);
	LoggerWriteMessage(message);
}

void LogSellToCustomerFailure(char* productName, char* customerName, TMoney price)
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Did not sell %s to %s", productName, customerName);
	LoggerWriteMessage(message);
}

void LogAddInventoryFromFile(TProductID productID, TMoney price)
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Added To Inventory: %d %.2f", productID, price);
	LoggerWriteMessage(message);
}

void LogCreateInventoryFile()
{
	char message[MAX_NAME_LEN];
	sprintf(message, "Saved Inventory Data To File");

	LoggerWriteMessage(message);
}

void LoggerCleanup()
{
	fclose(loggerFile);
}
